<?php

class DashboardController extends BaseController {

    public function __construct($registry) {
        parent::__construct($registry);
    }
    
    public function index() {
        
    }

    public function overviewMarketMenkeu() {

      $this->view->content = (object) array(

          'title' => 'Dashboard: Market Watch',
          'subtitle' => 'SUMBER: EXECUTIVE ECONOMIC DASHBOARD - BKF',
          'display_to_micro' => true,
          'display_to_macro' => true,

          'market_watch_data' => (object) array(

              'test' => true

            )

        );

      $this->view->render('Template-BKFAPI');

    }

    public function overviewMakroMenkeu() {

      $fetch = new DataOverview($this->registry);

      $dataDashboardBKF = $fetch->getBKFDashboard();
      $dataThresholdBKF = $fetch->getBKFThreshold();

      $indexBIRate = 0;
      $indexInflasi = 0;
      $indexIKK = 0;
      $indexPMA = 0;
      $indexPMDN = 0;
      $indexICP = 0;
      $indexOilLifting = 0;
      $indexKonsumsi = 0;
      $indexEkspor = 0;
      $indexImpor = 0;
      $indexNetEksim = 0;

      for ($i=count($dataDashboardBKF) - 1; $i>=0; $i--) {

        if (($indexBIRate == 0) && ($dataDashboardBKF[$i]->get_bi_rate() != '')) { $indexBIRate = $i; }
        if (($indexInflasi == 0) && ($dataDashboardBKF[$i]->get_inflasi() != '')) { $indexInflasi = $i; }
        if (($indexIKK == 0) && ($dataDashboardBKF[$i]->get_ikk() != '')) { $indexIKK = $i; }
        if (($indexPMA == 0) && ($dataDashboardBKF[$i]->get_pma() != '')) { $indexPMA = $i; }
        if (($indexPMDN == 0) && ($dataDashboardBKF[$i]->get_pmdn() != '')) { $indexPMDN = $i; }
        if (($indexICP == 0) && ($dataDashboardBKF[$i]->get_icp() != '')) { $indexICP = $i; }
        if (($indexOilLifting == 0) && ($dataDashboardBKF[$i]->get_oil_lifting() != '')) { $indexOilLifting = $i; }
        if (($indexKonsumsi == 0) && ($dataDashboardBKF[$i]->get_konsumsi() != '')) { $indexKonsumsi = $i; }
        if (($indexEkspor == 0) && ($dataDashboardBKF[$i]->get_ekspor() != '')) { $indexEkspor = $i; }
        if (($indexImpor == 0) && ($dataDashboardBKF[$i]->get_impor() != '')) { $indexImpor = $i; }
        if (($indexNetEksim == 0) && ($dataDashboardBKF[$i]->get_net_eksim() != '')) { $indexNetEksim = $i; }

      }

      $indexInflasiY0 = 0;

      for ($i=count($dataDashboardBKF) - 1; $i>=0; $i--) {

        if ($dataDashboardBKF[$i]->get_periode() == '01-01-2015') { $indexInflasiY0 = $i; }

      }

      $sumICP = 0;
      $countICP = 0;

      for ($i=$indexInflasiY0; $i<=$indexICP; $i++) {

        if ($dataDashboardBKF[$i]->get_icp() > 0) { $countICP++; $sumICP += $dataDashboardBKF[$i]->get_icp(); }

      }

      $sumOilLifting = 0;
      $countOilLifting = 0;

      for ($i=$indexInflasiY0; $i<=$indexOilLifting; $i++) {

        if ($dataDashboardBKF[$i]->get_oil_lifting() > 0) { $countOilLifting++; $sumOilLifting += $dataDashboardBKF[$i]->get_oil_lifting(); }

      }

      $indexPMAPMDN = 0;

      for ($i=count($dataDashboardBKF) - 1; $i>=0; $i--) {

        if ((substr($dataDashboardBKF[$i]->get_periode(),0,5) == '01-03') && ($dataDashboardBKF[$i]->get_pma() > 0)) { $indexPMAPMDN = $i; break; } 

      }

      $sumPMA = 0;

      for ($i=$indexPMAPMDN; $i<=$indexPMA; $i++) {

        if ($dataDashboardBKF[$i]->get_pma() > 0) { $sumPMA += $dataDashboardBKF[$i]->get_pma(); }

      }

      $sumPMDN = 0;

      for ($i=$indexPMAPMDN; $i<=$indexPMDN; $i++) {

        if ($dataDashboardBKF[$i]->get_pmdn() > 0) { $sumPMDN += $dataDashboardBKF[$i]->get_pmdn(); }

      }

      $indexBIRateT = 0;
      $indexInflasiT = 0;
      $indexIKKT = 0;
      $indexPMAT = 0;
      $indexPMDNT = 0;
      $indexICPT = 0;
      $indexOilLiftingT = 0;
      $indexKonsumsiT = 0;
      $indexEksporT = 0;
      $indexImporT = 0;

      for ($i=0; $i<count($dataThresholdBKF); $i++) {

        if ($dataThresholdBKF[$i]->get_indeks() == 'BI Rate') { $indexBIRateT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'Inflasi') { $indexInflasiT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'Indeks Keyakinan Konsumen') { $indexIKKT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'PMA') { $indexPMAT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'PMDN') { $indexPMDNT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'ICP') { $indexICPT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'Oil Lifting') { $indexOilLiftingT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'Konsumsi') { $indexKonsumsiT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'Ekspor') { $indexEksporT = $i; }
        if ($dataThresholdBKF[$i]->get_indeks() == 'Impor') { $indexImporT = $i; }

      }

      $lineBIRates = array();
      $lineBIDates = array();

      for ($i=0; $i<=$indexBIRate; $i++) {

        $lineBIRates[] = str_replace(',', '.', $dataDashboardBKF[$i]->get_bi_rate());
        $lineBIDates[] = substr($dataDashboardBKF[$i]->get_periode(),3,2) . '-' . substr($dataDashboardBKF[$i]->get_periode(),8,2);

      }

      $lineInflasiRates = array();
      $lineInflasiDates = array();

      for ($i=0; $i<=$indexInflasi; $i++) {

        $lineInflasiRates[] = str_replace(',', '.', $dataDashboardBKF[$i]->get_inflasi());
        $lineInflasiDates[] = substr($dataDashboardBKF[$i]->get_periode(),3,2) . '-' . substr($dataDashboardBKF[$i]->get_periode(),8,2);

      }

      $this->view->content = (object) array(

          'title' => 'Dashboard: Indikator Ekonomi Makro',
          'subtitle' => 'SUMBER DATA: ECONOMIC EXECUTIVE DASHBOARD - BKF',
          'type' => 'overview-default',
          'display_to_micro' => true,
          'display_to_market' => true,

          'tilegroups' => array(

              (object) array(

                'title' => 'Stabilitas',
                'type' => 'basic',

                'tiles' => array(

                    (object) array(

                        'type' => 'dial',
                        'title' => 'BI Rate (%)<br/>' . date('F-Y', strtotime($dataDashboardBKF[$indexBIRate]->get_periode())),
                        'subtitle' => 'bps',
                        'subtitle_value' => ($dataDashboardBKF[$indexBIRate]->get_bi_rate() - $dataDashboardBKF[$indexBIRate-1]->get_bi_rate()),
                        'max_value' => $dataThresholdBKF[$indexBIRateT]->get_max(),
                        'min_value' => $dataThresholdBKF[$indexBIRateT]->get_min(),
                        'value' => $dataDashboardBKF[$indexBIRate]->get_bi_rate(),
                        'up_down' => (object) array(

                            'target_direction' => 'down',
                            'value' => $dataDashboardBKF[$indexBIRate]->get_bi_rate() - $dataDashboardBKF[$indexBIRate-1]->get_bi_rate()

                          ),

                        'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexBIRateT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexBIRateT]->get_threshold3()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexBIRateT]->get_threshold3(), 
                              'to' => $dataThresholdBKF[$indexBIRateT]->get_threshold4()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexBIRateT]->get_threshold4(), 
                              'to' => $dataThresholdBKF[$indexBIRateT]->get_max()

                            )

                          ),

                        'detail' => (object) array(

                            'type' => 'line',
                            'title' => 'BI Rate - Detail',

                            'datasets' => array(

                                (object) array(

                                  'name' => 'BI Rate (%)',
                                  'values' => $lineBIRates

                                  )

                              ),

                            'categories' => $lineBIDates

                          )

                      ),

                    (object) array(

                        'type' => 'dial',
                        'title' => 'Inflasi (YOY) (%)<br/>' . date('F-Y', strtotime($dataDashboardBKF[$indexInflasi]->get_periode())),
                        'subtitle' => 'YTD (%)',
                        'subtitle_value' => round((($dataDashboardBKF[$indexInflasiY0]->get_inflasi() - $dataDashboardBKF[$indexInflasi]->get_inflasi()) / $dataDashboardBKF[$indexInflasiY0]->get_inflasi()) - 1, 2),
                        'max_value' => $dataThresholdBKF[$indexInflasiT]->get_max(),
                        'min_value' => $dataThresholdBKF[$indexInflasiT]->get_min(),
                        'value' => $dataDashboardBKF[$indexInflasi]->get_inflasi(),
                        'up_down' => (object) array(

                            'target_direction' => 'down',
                            'value' => $dataDashboardBKF[$indexInflasi]->get_inflasi() - $dataDashboardBKF[$indexInflasi-1]->get_inflasi()

                          ),

                        'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexInflasiT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexInflasiT]->get_threshold1()

                            ),

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexInflasiT]->get_threshold4(), 
                              'to' => $dataThresholdBKF[$indexInflasiT]->get_max()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexInflasiT]->get_threshold1(), 
                              'to' => $dataThresholdBKF[$indexInflasiT]->get_threshold2()

                            ),

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexInflasiT]->get_threshold3(), 
                              'to' => $dataThresholdBKF[$indexInflasiT]->get_threshold4()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexInflasiT]->get_threshold2(), 
                              'to' => $dataThresholdBKF[$indexInflasiT]->get_threshold3()

                            )

                          ),

                        'detail' => (object) array(

                            'type' => 'line',
                            'title' => 'Inflasi - Detail',

                            'datasets' => array(

                                (object) array(

                                  'name' => 'Inflasi (%)',
                                  'values' => $lineInflasiRates

                                  )

                              ),

                            'categories' => $lineInflasiDates

                          )

                      )

                  )

                ),

              (object) array(

                'title' => 'Konsumsi',
                'type' => 'basic',

                'tiles' => array(

                    (object) array(

                      'type' => 'dial',
                      'title' => 'Indeks Keyakinan<br/>Konsumen',
                      'subtitle' => 'Perubahan (M-1)',
                      'subtitle_value' => round($dataDashboardBKF[$indexIKK]->get_ikk() - $dataDashboardBKF[$indexIKK-1]->get_ikk(), 2),
                      'max_value' => $dataThresholdBKF[$indexIKKT]->get_max(),
                      'min_value' => $dataThresholdBKF[$indexIKKT]->get_min(),
                      'value' => $dataDashboardBKF[$indexIKK]->get_ikk(),
                      'up_down' => (object) array(

                            'target_direction' => 'up',
                            'value' => $dataDashboardBKF[$indexIKK]->get_ikk() - $dataDashboardBKF[$indexIKK-1]->get_ikk()

                          ),

                      'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexIKKT]->get_threshold2(), 
                              'to' => $dataThresholdBKF[$indexIKKT]->get_max()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexIKKT]->get_threshold1(), 
                              'to' => $dataThresholdBKF[$indexIKKT]->get_threshold2()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexIKKT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexIKKT]->get_threshold1()

                            )

                          )

                    )

                  )

                ),

              (object) array(

                'title' => 'Investasi',
                'type' => 'extra-center',

                'center_content' => '<h4>Triliun Rupiah</h4><p>' . date('F Y', strtotime('01-01-' . substr($dataDashboardBKF[$indexPMA]->get_periode(), 6, 4))) . ' - ' . date('F Y', strtotime($dataDashboardBKF[$indexPMA]->get_periode())) . '<p><br/><h4>Total Investasi Langsung (Akumulasi)</h4><p>' . round(($sumPMA + $sumPMDN) / 1000, 2) . '</p>',

                'tiles' => array(

                    (object) array(

                      'type' => 'dial',
                      'title' => 'PMA',
                      'subtitle' => 'Nilai Akumulasi',
                      'subtitle_value' => round($sumPMA / 1000, 2),
                      'max_value' => $dataThresholdBKF[$indexPMAT]->get_max(),
                      'min_value' => $dataThresholdBKF[$indexPMAT]->get_min(),
                      'value' => round($dataDashboardBKF[$indexPMA]->get_pma() / 1000, 2),

                      'up_down' => (object) array(

                            'target_direction' => 'up',
                            'value' => $dataDashboardBKF[$indexPMA]->get_pma() - $dataDashboardBKF[$indexPMA-3]->get_pma()

                          ),

                      'green_zones' => array(

                          (object) array( 

                            'from' => $dataThresholdBKF[$indexPMAT]->get_threshold2(), 
                            'to' => $dataThresholdBKF[$indexPMAT]->get_threshold3()

                          )

                        ),

                      'yellow_zones' => array(

                          (object) array( 

                            'from' => $dataThresholdBKF[$indexPMAT]->get_threshold1(), 
                            'to' => $dataThresholdBKF[$indexPMAT]->get_threshold2()

                          )
                        ),

                      'red_zones' => array(

                          (object) array( 

                            'from' => $dataThresholdBKF[$indexPMAT]->get_min(), 
                            'to' => $dataThresholdBKF[$indexPMAT]->get_threshold1()

                          )

                        )

                    ),

                  (object) array(

                      'type' => 'dial',
                      'title' => 'PMDN',
                      'subtitle' => 'Nilai Akumulasi',
                      'subtitle_value' => round($sumPMDN / 1000, 2),
                      'max_value' => $dataThresholdBKF[$indexPMDNT]->get_max(),
                      'min_value' => $dataThresholdBKF[$indexPMDNT]->get_min(),
                      'value' => round($dataDashboardBKF[$indexPMDN]->get_pmdn() / 1000, 2),

                      'up_down' => (object) array(

                            'target_direction' => 'up',
                            'value' => $dataDashboardBKF[$indexPMDN]->get_pmdn() - $dataDashboardBKF[$indexPMDN-3]->get_pmdn()

                          ),

                      'green_zones' => array(

                          (object) array( 

                            'from' => $dataThresholdBKF[$indexPMDNT]->get_threshold2(), 
                            'to' => $dataThresholdBKF[$indexPMDNT]->get_threshold3()

                          )

                        ),

                      'yellow_zones' => array(

                          (object) array( 

                            'from' => $dataThresholdBKF[$indexPMDNT]->get_threshold1(), 
                            'to' => $dataThresholdBKF[$indexPMDNT]->get_threshold2()

                          )

                        ),

                      'red_zones' => array(

                          (object) array( 

                            'from' => $dataThresholdBKF[$indexPMDNT]->get_min(), 
                            'to' => $dataThresholdBKF[$indexPMDNT]->get_threshold1()

                          )

                        )

                    )

                  )

                ),

              (object) array(

                'title' => 'Minyak',
                'type' => 'basic',

                'tiles' => array(

                    (object) array(

                        'type' => 'dial',
                        'title' => 'ICP (US$)<br/>' . date('F-Y', strtotime($dataDashboardBKF[$indexICP]->get_periode())),
                        'subtitle' => 'Rata-rata (US$)',
                        'subtitle_value' => round($sumICP / $countICP, 2),
                        'max_value' => $dataThresholdBKF[$indexICPT]->get_max(),
                        'min_value' => $dataThresholdBKF[$indexICPT]->get_min(),
                        'value' => $dataDashboardBKF[$indexICP]->get_icp(),

                        'up_down' => (object) array(

                            'target_direction' => 'down',
                            'value' => $dataDashboardBKF[$indexICP]->get_icp() - $dataDashboardBKF[$indexICP-1]->get_icp()

                          ),

                        'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexICPT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexICPT]->get_threshold1()

                            ),

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexICPT]->get_threshold4(), 
                              'to' => $dataThresholdBKF[$indexICPT]->get_max()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexICPT]->get_threshold1(), 
                              'to' => $dataThresholdBKF[$indexICPT]->get_threshold2()

                            ),

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexICPT]->get_threshold3(), 
                              'to' => $dataThresholdBKF[$indexICPT]->get_threshold4()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexICPT]->get_threshold2(), 
                              'to' => $dataThresholdBKF[$indexICPT]->get_threshold3()

                            )

                          )

                      ),

                    (object) array(

                        'type' => 'dial',
                        'title' => 'Oil Lifting (Ribu Barrel)<br/>' . date('F-Y', strtotime($dataDashboardBKF[$indexOilLifting]->get_periode())),
                        'subtitle' => 'Rata-rata',
                        'subtitle_value' => round($sumOilLifting / $countOilLifting, 2),
                        'max_value' => $dataThresholdBKF[$indexOilLiftingT]->get_max(),
                        'min_value' => $dataThresholdBKF[$indexOilLiftingT]->get_min(),
                        'value' => $dataDashboardBKF[$indexOilLifting]->get_oil_lifting(),

                        'up_down' => (object) array(

                            'target_direction' => 'up',
                            'value' => $dataDashboardBKF[$indexOilLifting]->get_oil_lifting() - $dataDashboardBKF[$indexOilLifting-1]->get_oil_lifting()

                          ),

                        'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexOilLiftingT]->get_threshold2(), 
                              'to' => $dataThresholdBKF[$indexOilLiftingT]->get_max()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexOilLiftingT]->get_threshold1(), 
                              'to' => $dataThresholdBKF[$indexOilLiftingT]->get_threshold2()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexOilLiftingT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexOilLiftingT]->get_threshold1()

                            )

                          )

                      ),

                    (object) array(

                        'type' => 'dial',
                        'title' => 'Konsumsi (Juta KL)<br/>' . date('F-Y', strtotime($dataDashboardBKF[$indexKonsumsi]->get_periode())),
                        'subtitle' => 'YTD (Akumulasi)',
                        'subtitle_value' => 0,
                        'max_value' => $dataThresholdBKF[$indexKonsumsiT]->get_max(),
                        'min_value' => $dataThresholdBKF[$indexKonsumsiT]->get_min(),
                        'value' => round($dataDashboardBKF[$indexKonsumsi]->get_konsumsi() / 1000000, 2),

                        'up_down' => (object) array(

                            'target_direction' => 'down',
                            'value' => $dataDashboardBKF[$indexKonsumsi]->get_konsumsi() - $dataDashboardBKF[$indexKonsumsi-1]->get_konsumsi()

                          ),

                        'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexKonsumsiT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexKonsumsiT]->get_threshold1()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexKonsumsiT]->get_threshold1(), 
                              'to' => $dataThresholdBKF[$indexKonsumsiT]->get_threshold2()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexKonsumsiT]->get_threshold2(), 
                              'to' => $dataThresholdBKF[$indexKonsumsiT]->get_max()

                            )

                          )

                      )

                  )

                ),

              (object) array(

                'title' => 'Ekspor/Impor',
                'type' => 'extra-center',

                'center_content' => '<h4>Miliar US$</h4><p>' . date('F Y', strtotime($dataDashboardBKF[$indexEkspor]->get_periode())) . '<p><br/><h4>Net Ekspor Impor</h4><p>' . round(($dataDashboardBKF[$indexEkspor]->get_ekspor() - $dataDashboardBKF[$indexEkspor]->get_impor()) / 1000, 2) . '</p>',

                'tiles' => array(

                    (object) array(

                        'type' => 'dial',
                        'title' => 'Ekspor',
                        'subtitle' => 'YOY (%)',
                        'subtitle_value' => round(($dataDashboardBKF[$indexEkspor]->get_ekspor() - $dataDashboardBKF[$indexEkspor - 12]->get_ekspor()) / 1000, 2),
                        'max_value' => $dataThresholdBKF[$indexEksporT]->get_max(),
                        'min_value' => $dataThresholdBKF[$indexEksporT]->get_min(),
                        'value' => round($dataDashboardBKF[$indexEkspor]->get_ekspor() / 1000, 2),

                        'up_down' => (object) array(

                            'target_direction' => 'up',
                            'value' => $dataDashboardBKF[$indexEkspor]->get_ekspor() - $dataDashboardBKF[$indexEkspor-1]->get_ekspor()

                          ),

                        'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexEksporT]->get_threshold2(), 
                              'to' => $dataThresholdBKF[$indexEksporT]->get_max()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexEksporT]->get_threshold1(), 
                              'to' => $dataThresholdBKF[$indexEksporT]->get_threshold2()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexEksporT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexEksporT]->get_threshold1()

                            )

                          )

                      ),

                      (object) array(

                        'type' => 'dial',
                        'title' => 'Impor',
                        'subtitle' => 'YOY (%)',
                        'subtitle_value' => round(($dataDashboardBKF[$indexImpor]->get_impor() - $dataDashboardBKF[$indexImpor - 12]->get_impor()) / 1000, 2),
                        'max_value' => $dataThresholdBKF[$indexImporT]->get_max(),
                        'min_value' => $dataThresholdBKF[$indexImporT]->get_min(),
                        'value' => round($dataDashboardBKF[$indexImpor]->get_impor() / 1000, 2),

                        'up_down' => (object) array(

                            'target_direction' => 'down',
                            'value' => $dataDashboardBKF[$indexImpor]->get_impor() - $dataDashboardBKF[$indexImpor-1]->get_impor()

                          ),

                        'green_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexImporT]->get_min(), 
                              'to' => $dataThresholdBKF[$indexImporT]->get_threshold1()

                            ),

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexImporT]->get_threshold4(), 
                              'to' => $dataThresholdBKF[$indexImporT]->get_max()

                            )

                          ),

                        'yellow_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexImporT]->get_threshold1(), 
                              'to' => $dataThresholdBKF[$indexImporT]->get_threshold2()

                            ),

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexImporT]->get_threshold3(), 
                              'to' => $dataThresholdBKF[$indexImporT]->get_threshold4()

                            )

                          ),

                        'red_zones' => array(

                            (object) array( 

                              'from' => $dataThresholdBKF[$indexImporT]->get_threshold2(), 
                              'to' => $dataThresholdBKF[$indexImporT]->get_threshold3()

                            )

                          )

                      )

                  )

                ),

            ),

          'disable_notifications' => true

        );

      $this->view->render('Template-Overview');

    }

    public function overviewMenkeu($mode=null) {

      $fetch = new DataOverview($this->registry);

      $dashLRAHariIni = $fetch->getLRAMenkeu();

      $belanjaPerpres = $fetch->getAPBNBelanja();
      $penerimaanPerpres = $fetch->getAPBNPenerimaan();
      $pembiayaanPerpres = $fetch->getAPBNPembiayaan();

      $dipaHariIni = $fetch->sumDIPABelanja();
      $pembiayaanHariIni = $fetch->sumRealisasiPembiayaanMenkeu();
      $belanjaHariIni = $fetch->sumRealisasiBelanjaMenkeu();
      $penerimaanHariIni = $fetch->sumRealisasiPenerimaanMenkeu();

      $kontrakHariIni =  $fetch->fetchStatusRealisasiKontrak();

      $belanjaBungaHariIni = $fetch->sumRealisasiBelanjaBunga();
      $belanjaBungaDIPA = $fetch->sumPaguBelanjaBungaMenkeu();

      $pengembalianPenerimaanHariIni = $fetch->sumPengembalianPenerimaanMenkeu();

      if (!isset($mode) || ($mode == 1)) {

        $belanjaPerpresTahunLalu = $fetch->getAPBNBelanjaTAYL();

        $lineBelanjaTahunIni = $fetch->fetchLineBelanja(Session::get('ta'));

        if ((''.Session::get('ta')) == date("Y")) {
          $lineBelanjaTahunLalu = $fetch->fetchLineBelanja(intval(Session::get('ta')) - 1);
        }

        $mainchartData = array();
        $mainchartData2 = array();

        if ((''.Session::get('ta')) == date("Y")) {
          $penerimaanPerpresTahunLalu = $fetch->getAPBNPenerimaanTAYL();
        }

        $linePenerimaanTahunIni = $fetch->fetchLinePenerimaan(Session::get('ta'));

        if ((''.Session::get('ta')) == date("Y")) {
          $linePenerimaanTahunLalu = $fetch->fetchLinePenerimaan(intval(Session::get('ta')) - 1);
        }

        $mainchartData3 = array();
        $mainchartData4 = array();

        if ((''.Session::get('ta')) == date("Y")) {

          $maxx = count($lineBelanjaTahunIni)-1;

        } else {

          $maxx = count($lineBelanjaTahunIni);

        }

        for($i = 0; $i<$maxx; $i++) {

          $mainchartData[] = round($lineBelanjaTahunIni[$i]->get_realisasi() / $belanjaPerpres * 1000) / 10;
          $mainchartData3[] = round($linePenerimaanTahunIni[$i]->get_realisasi() / $penerimaanPerpres * 1000) / 10 * -1;

        }

        if ((''.Session::get('ta')) == date("Y")) {
          for($i = 0; $i<12; $i++) {

            $mainchartData2[] = round($lineBelanjaTahunLalu[$i]->get_realisasi() / $belanjaPerpresTahunLalu * 1000) / 10;
            $mainchartData4[] = round($linePenerimaanTahunLalu[$i]->get_realisasi() / $penerimaanPerpresTahunLalu * 1000) / 10 * -1;

          }
        }

        if ((''.Session::get('ta')) == date("Y")) {

          $main_tile = (object) array(

            'type' => 'line',
            'stacked' => true,
            'disclaimer' => 'Data tahun lalu merupakan data tiap <em><strong>akhir</em></strong> bulan bersangkutan.',
            'title' => 'Perkembangan Realisasi Belanja dan Penerimaan',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi Belanja (Tahun Ini)',
                  'values' => $mainchartData

                  ),
                (object) array(

                  'name' => 'Persentase Realisasi Belanja (Tahun Lalu)',
                  'values' => $mainchartData2

                  )

              ),

            'secondary_datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi Penerimaan (Tahun Ini)',
                  'values' => $mainchartData3

                  ),
                (object) array(

                  'name' => 'Persentase Realisasi Penerimaan (Tahun Lalu)',
                  'values' => $mainchartData4

                  )

              ),

            'categories' => array('JAN', 'FEB', 'MAR', 'APR', 'MEI', 'JUN', 'JUL', 'AGU', 'SEP', 'OKT', 'NOV', 'DES'),

            'colors' => array('#ff6666', '#1f77b4')

          );

        } else {

          $main_tile = (object) array(

            'type' => 'line',
            'stacked' => true,
            'title' => 'Perkembangan Realisasi Belanja dan Penerimaan',
            'disclaimer' => 'Data tahun lalu merupakan data tiap <em><strong>akhir</em></strong> bulan bersangkutan.',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi Belanja (Tahun Ini)',
                  'values' => $mainchartData

                  )

              ),

            'secondary_datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi Penerimaan (Tahun Ini)',
                  'values' => $mainchartData3

                  )

              ),

            'categories' => array('JAN', 'FEB', 'MAR', 'APR', 'MEI', 'JUN', 'JUL', 'AGU', 'SEP', 'OKT', 'NOV', 'DES'),

            'colors' => array('#ff6666', '#1f77b4')

          );

        }

      }  else if ($mode == 2) {

        $detailRealisasi = $fetch->fetchNominalPaguBelanjaPenerimaanMenkeu();

        $mainchartData = array();
        $mainchartData2 = array();
        $mainchartData3 = array();
        $mainchartData4 = array();

        if ((''.Session::get('ta')) == date("Y")) {

        $disclaimer = 'Realisasi tahun lalu merupakan data sampai dengan <em><strong>akhir</strong></em> bulan ' . date('m') . '/' . (Session::get('ta') - 1);

        } else {

          $disclaimer = 'Realisasi tahun lalu merupakan data sampai dengan <em><strong>akhir</strong></em> bulan 12/' . (Session::get('ta') - 1);

        }

        foreach ($detailRealisasi as $did=>$detailItem) {

          if (substr($detailItem->get_akun(), 0, 1) == '4') {

            $mainchartData2[] = round(($detailItem->get_realisasi() * -1) / $detailItem->get_pagu() * 1000) / 10;
            $mainchartData[] = 0;

            if ($detailItem->get_pagu_lalu() <= 0) {

              $mainchartData3[] = 0;
              $mainchartData4[] = 0;

            } else {

              $mainchartData4[] = round(($detailItem->get_realisasi_lalu() * -1) / $detailItem->get_pagu_lalu() * 1000) / 10;
              $mainchartData3[] = 0;

            }

          } else {
              
            if (((''.Session::get('ta')) != '2015') || ($did != 15)) {
                
                $mainchartData[] = round($detailItem->get_realisasi() / $detailItem->get_pagu() * 1000) / 10;
                $mainchartData2[] = 0;
        
                if ($detailItem->get_pagu_lalu() <= 0) {
        
                  $mainchartData3[] = 0;
                  $mainchartData4[] = 0;
        
                } else {
        
                  $mainchartData3[] = round($detailItem->get_realisasi_lalu() / $detailItem->get_pagu_lalu() * 1000) / 10;
                  $mainchartData4[] = 0;
        
                }
                
            }

          }

        }
        
        if ((''.Session::get('ta')) == '2015') {
            
            $mainchartData[] = round($dashLRAHariIni[49]->get_jumlah() / $dashLRAHariIni[49]->get_apbn() * 1000) / 10;
            $mainchartData2[] = 0;
            
            $mainchartData3[] = round($detailRealisasi[15]->get_realisasi_lalu() / $detailRealisasi[15]->get_pagu_lalu() * 1000) / 10;
            $mainchartData4[] = 0;
            
            $mainchartData[] = round($dashLRAHariIni[50]->get_jumlah() / $dashLRAHariIni[50]->get_apbn() * 1000) / 10;
            $mainchartData2[] = 0;
            
            $mainchartData3[] = 0;
            $mainchartData4[] = 0;
                        
            $mainChartCats = array('Pajak', 'PNBP', 'Hibah', 'Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Bagi Hasil', 'DAU', 'DAK', 'OtSus', 'DIY', 'Trans. Lainnya', 'Dana Desa'); 
        
        } else {
            
            $mainChartCats = array('Pajak', 'PNBP', 'Hibah', 'Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Bagi Hasil', 'DAU', 'DAK', 'OtSus', 'Trans. Lainnya', 'DIY');
            
        }

        $main_tile = (object) array(

          'type' => 'bar',
          'title' => 'Persentase Realisasi Belanja, Pendapatan dan Hibah',

          'datasets' => array(

              (object) array(

                'name' => 'Persentase Realisasi Penerimaan (Tahun Lalu)',
                'values' => $mainchartData4

                ),

              (object) array(

                'name' => 'Persentase Realisasi Penerimaan',
                'values' => $mainchartData2

                ),

              (object) array(

                'name' => 'Persentase Realisasi Belanja (Tahun Lalu)',
                'values' => $mainchartData3

                ),

              (object) array(

                'name' => 'Persentase Realisasi Belanja',
                'values' => $mainchartData

                )             

            ),

          'categories' => $mainChartCats,

          'groups' => array(

              array('Persentase Realisasi Penerimaan', 'Persentase Realisasi Belanja'),
              array('Persentase Realisasi Penerimaan (Tahun Lalu)', 'Persentase Realisasi Belanja (Tahun Lalu)')

            ),

          'colors' => array('#74baeb', '#1f77b4', '#ffaeae', '#ff6666'),

          'disclaimer' => $disclaimer,

          'rotate_height' => 500

        );

      } else if ($mode == 3) {

        $detailRealisasi = $fetch->fetchNominalPaguBelanjaPenerimaanMenkeu();

        $mainchartData = array();
        $mainchartData2 = array();
        $mainchartData3 = array();
        $mainchartData4 = array();

        if ((''.Session::get('ta')) == date("Y")) {

          $disclaimer = 'Realisasi tahun lalu merupakan data sampai dengan <em><strong>akhir</strong></em> bulan ' . date('m') . '/' . (Session::get('ta') - 1);

        } else {

          $disclaimer = 'Realisasi tahun lalu merupakan data sampai dengan <em><strong>akhir</strong></em> bulan 12/' . (Session::get('ta') - 1);

        }

        foreach ($detailRealisasi as $did=>$detailItem) {

          if (substr($detailItem->get_akun(), 0, 1) == '4') {

            $mainchartData2[] = round($detailItem->get_realisasi() * -1 / 1000000000000, 2);
            $mainchartData[] = 0;

            $mainchartData4[] = round($detailItem->get_realisasi_lalu() * -1 / 1000000000000, 2);
            $mainchartData3[] = 0;

          } else {
              
            if (((''.Session::get('ta')) != '2015') || ($did != 15)) {

                $mainchartData[] = round($detailItem->get_realisasi() / 1000000000000, 2);
                $mainchartData2[] = 0;
    
                $mainchartData3[] = round($detailItem->get_realisasi_lalu() / 1000000000000, 2);
                $mainchartData4[] = 0;
            
            }

          }

        }
        
        if ((''.Session::get('ta')) == '2015') {
            
            $mainchartData[] = round($dashLRAHariIni[49]->get_jumlah() / 1000000000000, 2);
            $mainchartData2[] = 0;
            
            $mainchartData3[] = round($detailRealisasi[15]->get_realisasi_lalu() / 1000000000000, 2);
            $mainchartData4[] = 0;
            
            $mainchartData[] = round($dashLRAHariIni[50]->get_jumlah() / 1000000000000, 2);
            $mainchartData2[] = 0;
            
            $mainchartData3[] = 0;
            $mainchartData4[] = 0;
                        
            $mainChartCats = array('Pajak', 'PNBP', 'Hibah', 'Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Bagi Hasil', 'DAU', 'DAK', 'OtSus', 'DIY', 'Trans. Lainnya', 'Dana Desa'); 
        
        } else {
            
            $mainChartCats = array('Pajak', 'PNBP', 'Hibah', 'Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Bagi Hasil', 'DAU', 'DAK', 'OtSus', 'Trans. Lainnya', 'DIY');
            
        }

        $main_tile = (object) array(

          'type' => 'bar',
          'stacked' => true,
          'title' => 'Nominal Realisasi Belanja, Pendapatan dan Hibah',

          'datasets' => array(

              (object) array(

                'name' => 'Realisasi Penerimaan Tahun Lalu (Triliun Rupiah)',
                'values' => $mainchartData4

                ),

              (object) array(

                'name' => 'Realisasi Penerimaan (Triliun Rupiah)',
                'values' => $mainchartData2

                ),

              (object) array(

                'name' => 'Realisasi Belanja Tahun Lalu (Triliun Rupiah)',
                'values' => $mainchartData3

                ),

              (object) array(

                'name' => 'Realisasi Belanja (Triliun Rupiah)',
                'values' => $mainchartData

                ),

            ),

          'categories' => $mainChartCats,

          'groups' => array(

              array('Realisasi Penerimaan Tahun Lalu (Triliun Rupiah)', 'Realisasi Belanja Tahun Lalu (Triliun Rupiah)'),
              array('Realisasi Penerimaan (Triliun Rupiah)', 'Realisasi Belanja (Triliun Rupiah)')

            ),

          'colors' => array('#74baeb', '#1f77b4', '#ffaeae', '#ff6666'),

          'disclaimer' => $disclaimer,

          'rotate_height' => 500

        );
        
      } else if ($mode == 4) {

        $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerBAMenkeu();

        $mainchartData = array();
        $mainchartLabel = array();
        $mainchartLegend = array();
        $mainchartExtras = array();

        $mainchartExtras[0] = array();

        foreach ($realisasiPerUnit as $unitData) { 

          $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
          $mainchartExtras[0][] = round($unitData->get_realisasi() / 10000000000) / 100 . ' Triliun';
          $mainchartLabel[] = $unitData->get_unit();

        }

        $legendLabels = $fetch->fetchNamaUnit(5, $mainchartLabel);

        foreach ($mainchartLabel as $lid=>$label) {

          foreach ($legendLabels as $legend) {

            if ($label == $legend->get_kode_unit()) {

              $mainchartLegend[$lid] = $legend->get_nama_unit();

            }

          }

        }

        //var_dump($legendLabels);

        $main_tile = (object) array(

          'type' => 'bar',
          'stacked' => true,
          'title' => 'Persentase Realisasi Belanja per K/L',

          'datasets' => array(

              (object) array(

                'name' => 'Persentase Realisasi',
                'values' => $mainchartData

                )

            ),

          'categories' => $mainchartLabel,
          'tooltips' => $mainchartLegend,
          'tooltip_extras' => $mainchartExtras,
          'rotate_height' => 1200

        );

      } else if ($mode == 5) {

        $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerBAMenkeu();

        $mainchartData = array();
        $mainchartLabel = array();
        $mainchartLegend = array();

        $mainchartExtras = array();

        $mainchartExtras[0] = array();

        foreach ($realisasiPerUnit as $unitData) { 

          if ($unitData->get_unit() != '999') {

            $mainchartData[] = round($unitData->get_realisasi() / 10000000000) / 100;
            $mainchartExtras[0][] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10 . ' %';
            $mainchartLabel[] = $unitData->get_unit();

          } else {

            $disclaimer = 'Realisasi untuk BA999 (Bendahara Umum Negara) sebesar ' . (round($unitData->get_realisasi() / 10000000000) / 100) . ' Triliun (' . round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10 . ' %)';

          }

        }

        $legendLabels = $fetch->fetchNamaUnit(5, $mainchartLabel);

        foreach ($mainchartLabel as $lid=>$label) {

          foreach ($legendLabels as $legend) {

            if ($label == $legend->get_kode_unit()) {

              $mainchartLegend[$lid] = $legend->get_nama_unit();

            }

          }

        }

        $main_tile = (object) array(

          'type' => 'bar',
          'stacked' => true,
          'title' => 'Nominal Realisasi Belanja per K/L (Tidak Termasuk BA 999)',

          'datasets' => array(

              (object) array(

                'name' => 'Nominal Realisasi (dalam Triliun Rupiah)',
                'values' => $mainchartData

                )

            ),

          'categories' => $mainchartLabel,
          'tooltips' => $mainchartLegend,
          'tooltip_extras' => $mainchartExtras,
          'disclaimer' => $disclaimer,
          'rotate_height' => 1200

        );

      } else if ($mode == 6) {

        $realisasiPerUnitPajak = $fetch->fetchRealisasiPenerimaanPajakPerBAMenkeu();
        $realisasiPerUnitPNBP = $fetch->fetchRealisasiPenerimaanPNBPPerBAMenkeu();

        $mainchartData = array();
        $mainchartData2 = array();
        $mainchartLabel = array();
        $mainchartLegend = array();

        foreach ($realisasiPerUnitPajak as $uid=>$unitData) { 

          $mainchartData[] = round($unitData->get_realisasi()/1000000000000, 2);
          $mainchartData2[] = round($realisasiPerUnitPNBP[$uid]->get_realisasi() / 1000000000000, 2);
          $mainchartLabel[] = $unitData->get_unit();

        }

        $legendLabels = $fetch->fetchNamaUnit(5, $mainchartLabel);

        foreach ($mainchartLabel as $lid=>$label) {

          foreach ($legendLabels as $legend) {

            if ($label == $legend->get_kode_unit()) {

              $mainchartLegend[$lid] = $legend->get_nama_unit();

            }

          }

        }

        $main_tile = (object) array(

          'type' => 'bar',
          'stacked' => true,
          'title' => 'Nominal Realisasi Penerimaan per K/L',

          'datasets' => array(

              (object) array(

                'name' => 'Nominal Realisasi Pajak (dalam Triliun Rupiah)',
                'values' => $mainchartData

                ),

              (object) array(

                'name' => 'Nominal Realisasi PNBP (dalam Triliun Rupiah)',
                'values' => $mainchartData2

                )

            ),

          'categories' => $mainchartLabel,
          'tooltips' => $mainchartLegend,
          'rotate_height' => 1200

        );

      } else if ($mode == 7) {

        $realisasiPenerimaanPerAkun = $fetch->realisasiPenerimaanPerAkunMenkeu();

        $mainchartData = array();
        $mainchartData2 = array();
        $mainchartLabel = array();
        $mainchartLegend = array();

        foreach ($realisasiPenerimaanPerAkun as $uid=>$unitData) { 

          $mainchartData[] = round(($unitData->get_realisasi() - $unitData->get_pengembalian())/1000000000, 2);
          $mainchartData2[] = round($unitData->get_pengembalian() / 1000000000, 2);
          $mainchartLegend[] = $unitData->get_deskripsi();

        }

        $main_tile = (object) array(

          'type' => 'bar',
          'stacked' => true,
          'title' => 'Nominal Realisasi Penerimaan Beserta Pengembalian Per Jenis',

          'datasets' => array(

              (object) array(

                'name' => 'Nominal Pengembalian (dalam Miliar Rupiah)',
                'values' => $mainchartData2

                ),

              (object) array(

                'name' => 'Nominal Pendapatan Netto (dalam Miliar Rupiah)',
                'values' => $mainchartData

                )

            ),

          'categories' => array('Cukai', 'PPN', 'BLU', 'PBB', 'Bea Masuk', 'Hibah', 'BUMN', 'BPHTB', 'PNBP Lain', 'Bea Keluar', 'Non-Migas', 'PPH', 'Pajak Lainnya', 'Migas'),
          'tooltips' => $mainchartLegend,
          'rotate_height' => 1200

        );

      }

      if ((''.Session::get('ta')) == date("Y")) {

        $subtitle = 'TAHUN INI SAMPAI DENGAN TANGGAL ' . date('d', time() - 24*60*60) . '/' . date('m');

      } else {

        $subtitle = 'TAHUN ' . Session::get('ta') . ' SAMPAI DENGAN TANGGAL 31/12';

      }

      if (($penerimaanHariIni - $belanjaHariIni) > 0) {

        $surplusDefisitColor = array('#37e564');

      } else if (($penerimaanHariIni - $belanjaHariIni) < ($penerimaanPerpres - $belanjaPerpres)) {

        $surplusDefisitColor = array('#ff6666');

      } else {

        $surplusDefisitColor = array('#ffdd40');

      }

      if (($penerimaanHariIni - $belanjaHariIni + $belanjaBungaHariIni) > 0) {

        $kesPrimerColor = array('#37e564');

      } else if (($penerimaanHariIni - $belanjaHariIni + $belanjaBungaHariIni) < ($penerimaanPerpres - $belanjaPerpres + $belanjaBungaDIPA)) {

        $kesPrimerColor = array('#ff6666');

      } else {

        $kesPrimerColor = array('#ffdd40');

      }

      $this->view->content = (object) array(

          'title' => 'Dashboard: Realisasi APBN',
          'subtitle' => $subtitle,
          'type' => 'overview-default',
          'display_to_macro' => true,
          'display_to_market' => true,

          'extras' => $dashLRAHariIni,

          'disclaimer' => 'Data pagu diambil berdasarkan UU APBN / UU APBN-P beserta Peraturan Presiden terkait, Realisasi berdasarkan Kas dan Netto.',

          'status_tiles' => array(

              (object) array(

                  'type' => 'gauge',
                  'title' => 'DIPA Belanja',
                  'subtitle' => round($dipaHariIni / 1000000000000, 2) . ' Triliun (' . round($dipaHariIni / $belanjaPerpres * 1000) / 10 . ' %) <br/>Dari Perpres ' . round($belanjaPerpres / 1000000000000, 2)  .' Triliun',
                  'value' => round($dipaHariIni / 1000000000000, 2),
                  'max_value' => round($belanjaPerpres / 1000000000000, 2)

                ),

              (object) array(

                  'type' => 'gauge',
                  'title' => 'Realisasi Belanja',
                  'subtitle' => round($belanjaHariIni / 1000000000000, 2) . ' Triliun (' . round($belanjaHariIni / $belanjaPerpres * 1000) / 10 . ' %) <br/>Dari Anggaran Belanja ' . round($belanjaPerpres / 1000000000000, 2) .' Triliun ',
                  'value' => round($belanjaHariIni / 1000000000000, 2),
                  'max_value' => round($belanjaPerpres / 1000000000000, 2)

                ),

              (object) array(

                  'type' => 'gauge',
                  'title' => 'Realisasi Pendapatan dan Hibah',
                  'subtitle' => round($penerimaanHariIni / 1000000000000, 2) . ' Triliun (' . round($penerimaanHariIni / $penerimaanPerpres * 1000) / 10 . ' %) <br/>Dari Target Penerimaan ' . round($penerimaanPerpres / 1000000000000, 2) .' Triliun <br/>Setelah dikurangi pengembalian penerimaan ' . round($pengembalianPenerimaanHariIni / 1000000000000, 2)  . ' Triliun',
                  'value' => round($penerimaanHariIni / 1000000000000, 2),
                  'max_value' => round($penerimaanPerpres / 1000000000000, 2)

                ),

              (object) array(

                  'type' => 'gauge',
                  'title' => 'Realisasi Pembiayaan',
                  'subtitle' => round($pembiayaanHariIni / 1000000000000, 2)  . ' Triliun (' . round($pembiayaanHariIni / $pembiayaanPerpres * 1000) / 10 . ' %) <br/>Dari Anggaran Pembiayaan ' . round($pembiayaanPerpres / 1000000000000, 2) .' Triliun ',
                  'value' => round($pembiayaanHariIni / 1000000000000, 2),
                  'max_value' => round($pembiayaanPerpres / 1000000000000, 2)

                ),

              (object) array(

                  'type' => 'dial',
                  'title' => 'Surplus/Defisit',
                  'subtitle' => round(($penerimaanHariIni - $belanjaHariIni) / 1000000000000, 2) . ' Triliun (' . round(($penerimaanHariIni - $belanjaHariIni) / ($penerimaanPerpres - $belanjaPerpres) * 1000) / 10 . ' %) <br/>Dari Defisit Anggaran ' . round(($penerimaanPerpres - $belanjaPerpres) / 1000000000000, 2)  .' Triliun ',
                  'value' => round(($penerimaanHariIni - $belanjaHariIni) / 1000000000000, 2),

                  'max_value' => round(($penerimaanPerpres - $belanjaPerpres) / 1000000000000) * -1,
                  'min_value' => round(($penerimaanPerpres - $belanjaPerpres) / 1000000000000),

                  'green_zones' => array(

                      (object) array( 

                        'from' => 0, 
                        'to' => round(($penerimaanPerpres - $belanjaPerpres) / 1000000000000) * -1

                      )

                    ),

                  'red_zones' => array(

                      (object) array( 

                        'from' => round(($penerimaanPerpres - $belanjaPerpres) / 1000000000000), 
                        'to' => 0

                      )

                    )

                ),

              (object) array(

                  'type' => 'dial',
                  'title' => 'Keseimbangan Primer',
                  'subtitle' => round(($penerimaanHariIni - $belanjaHariIni + $belanjaBungaHariIni) / 1000000000000, 2) . ' Triliun (' . round(($penerimaanHariIni - $belanjaHariIni + $belanjaBungaHariIni) / ($penerimaanPerpres - $belanjaPerpres + $belanjaBungaDIPA) * 1000) / 10 . ' %) <br/>Dari Anggaran ' . round(($penerimaanPerpres - $belanjaPerpres + $belanjaBungaDIPA) / 1000000000000, 2) .' Triliun ',
                  'max_value' => round(($penerimaanPerpres - $belanjaPerpres + $belanjaBungaDIPA) / 1000000000000)  * -1,
                  'min_value' => round(($penerimaanPerpres - $belanjaPerpres + $belanjaBungaDIPA) / 1000000000000),
                  'value' => round(($penerimaanHariIni - $belanjaHariIni + $belanjaBungaHariIni) / 1000000000000, 2),

                  'green_zones' => array(

                      (object) array( 

                        'from' => 0, 
                        'to' => round(($penerimaanPerpres - $belanjaPerpres + $belanjaBungaDIPA) / 1000000000000)  * -1

                      )

                    ),

                  'red_zones' => array(

                      (object) array( 

                        'from' => round(($penerimaanPerpres - $belanjaPerpres + $belanjaBungaDIPA) / 1000000000000), 
                        'to' => 0

                      )

                    )

                )

            ),

          'main_tile' => $main_tile,

          'disable_notifications' => true

        );

      $this->view->switchers = array();
      $this->view->switchers[] = 'Perkembangan Realisasi Belanja dan Penerimaan';
      $this->view->switchers[] = 'Persentase Realisasi Belanja, Pendapatan dan Hibah';
      $this->view->switchers[] = 'Nominal Realisasi Belanja, Pendapatan dan Hibah';
      $this->view->switchers[] = 'Persentase Realisasi Belanja per K/L';
      $this->view->switchers[] = 'Nominal Realisasi Belanja per K/L';

      $this->view->switchers[] = 'Nominal Realisasi Penerimaan per K/L';
      $this->view->switchers[] = 'Nominal Realisasi Penerimaan Beserta Pengembalian Per Jenis';

      $this->view->baseURL = URL . 'dashboard/overviewMenkeu/';
      
      //echo(json_encode($this->view->content));

      $this->view->render('Template-Overview');

    }

    public function overviewAdmin($mode=null) {

        $fetch = new DataOverview($this->registry);

        $belanjaHariIni = $fetch->fetchRealisasiPaguBelanja();
        $penerimaanHariIni = $fetch->sumRealisasiPenerimaan();
        $kontrakHariIni =  $fetch->fetchStatusRealisasiKontrak();
        $sp2dHariIni = $fetch->fetchRekapSP2DTahunIni($filter2);

        if (!isset($mode) || ($mode == 1)) {

          $detailRealisasi = $fetch->get_realisasi_dash_filter();

          $mainchartData = array();

          if ($detailRealisasi[0]->get_pagu_51() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_51() / $detailRealisasi[0]->get_pagu_51() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_52() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_52() / $detailRealisasi[0]->get_pagu_52() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_53() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_53() / $detailRealisasi[0]->get_pagu_53() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_54() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_54() / $detailRealisasi[0]->get_pagu_54() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_55() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_55() / $detailRealisasi[0]->get_pagu_55() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_56() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_56() / $detailRealisasi[0]->get_pagu_56() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_57() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_57() / $detailRealisasi[0]->get_pagu_57() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_58() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_58() / $detailRealisasi[0]->get_pagu_58() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_61() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_61() / $detailRealisasi[0]->get_pagu_61() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer'),
            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' %', $mainchartData[1] . ' %', $mainchartData[2] . ' %', $mainchartData[3] . ' %', $mainchartData[4] . ' %', $mainchartData[5] . ' %', $mainchartData[6] . ' %', $mainchartData[7] . ' %', $mainchartData[8] . ' %'),
                'colors' => array('#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4')

              )

          );

        }  else if ($mode == 2) {

          $detailRealisasi = $fetch->get_realisasi_numbers_dash_filter();

          $mainchartData = array();
          $mainchartData2 = array();

          if ($detailRealisasi[0]->get_belanja_51() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_51() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_52() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_52() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_53() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_53() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_54() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_54() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_55() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_55() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_56() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_56() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_57() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_57() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_58() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_58() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_61() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_61() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_41() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_41()  * -1 / 10000000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData2[] = 0;
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_42() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_42()  * -1 / 10000000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData2[] = 0;
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis',

            'datasets' => array(

                (object) array(

                  'name' => 'Realisasi Belanja (dalam Triliun Rupiah)',
                  'values' => $mainchartData

                  ),
                (object) array(

                  'name' => 'Realisasi Penerimaan (dalam Triliun Rupiah)',
                  'values' => $mainchartData2

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer', 'Pajak', 'PNBP'),

            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' Triliun', $mainchartData[1] . ' Triliun', $mainchartData[2] . ' Triliun', $mainchartData[3] . ' Triliun', $mainchartData[4] . ' Triliun', $mainchartData[5] . ' Triliun', $mainchartData[6] . ' Triliun', $mainchartData[7] . ' Triliun', $mainchartData[8] . ' Triliun', $mainchartData2[9] . ' Triliun', $mainchartData2[10] . ' Triliun'),
                'colors' => array('#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#1f77b4', '#1f77b4')

              ),

            'colors' => array('#ff6666', '#1f77b4')

          );
          
        } else if ($mode == 3) {

          $filtermain = array();

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnit(1,1);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Tertinggi per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );
          
        } else if ($mode == 4) {

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnit(1,2);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Terendah per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        } else if ($mode == 5) {

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(3,1);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(5, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Tertinggi per K/L',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        } else if ($mode == 6) {

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(3,2);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(5, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Terendah per K/L',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        } else if ($mode == 7) {

          $rekapUnit = $fetch->get_sp2d_rekap_tabel();

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'table-legacy-summary',
            'title' => 'Rekapitulasi Status SPM, SP2D, dan LHP Kanwil (Hari Ini)',

            'summary_rows' => $rekapUnit

          );

        }

        $this->view->content = (object) array(

            'title' => 'Dashboard',
            'type' => 'overview-default',

            'status_tiles' => array(

                (object) array(

                    'type' => 'pie',
                    'title' => 'Penerbitan SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Gaji',
                          'value' => $sp2dHariIni->get_gaji()

                          ),

                        (object) array(

                          'name' => 'Non Gaji',
                          'value' => $sp2dHariIni->get_non_gaji()

                          ),

                        (object) array(

                          'name' => 'Retur',
                          'value' => $sp2dHariIni->get_retur()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $sp2dHariIni->get_lainnya()

                          ),

                        (object) array(

                          'name' => 'Void',
                          'value' => $sp2dHariIni->get_void()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#CF8CD7', '#CCCCCC', '#FF6666')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Belanja',
                    'subtitle' => round($belanjaHariIni->get_realisasi() / 100000000000) / 10 . ' Triliun (' . round($belanjaHariIni->get_realisasi() / $belanjaHariIni->get_pagu() * 1000) / 10 . ' %) <br/>Dari Pagu Belanja ' . round($belanjaHariIni->get_pagu() / 100000000000) / 10 .' Triliun ',
                    'value' => round($belanjaHariIni->get_realisasi() / 100000000000) / 10,
                    'max_value' => round($belanjaHariIni->get_pagu() / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Penerimaan',
                    'subtitle' => round($penerimaanHariIni / 100000000000) / 10 . ' Triliun <br/>Tidak ada data pagu',
                    'value' => round($penerimaanHariIni / 100000000000) / 10,
                    'max_value' => round($penerimaanHariIni / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Pencairan Kontrak',
                    'subtitle' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10 . ' Triliun (' . round($kontrakHariIni->get_pencairan() / $kontrakHariIni->get_nilai_kontrak() * 1000) / 10 . ' %) <br/>Dari Total Nilai Kontrak ' . round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10 .' Triliun ',
                    'value' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10,
                    'max_value' => round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10

                  )

              ),

            'main_tile' => $main_tile,

            'notifications' => array()

          );

        $this->view->switchers = array();
        $this->view->switchers[] = 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja';
        $this->view->switchers[] = 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Tertinggi per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Terendah per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Tertinggi per K/L';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Terendah per K/L';
        $this->view->switchers[] = 'Rekapitulasi Status SPM, SP2D, dan LHP Kanwil (Hari Ini)';

        $this->view->baseURL = URL . 'dashboard/overviewAdmin/';
        
        //echo(json_encode($this->view->content));

        $this->view->render('Template-Overview');
        
    }

    public function overviewKanwil($mode, $unit=null) {

        $fetch = new DataOverview($this->registry);

        if (!isset($unit)) {

          $unit = Session::get('kd_satker');
          $this->view->extraURL = '';

        } else {

          $namaUnit = $fetch->getNamaUnit(3,substr($unit,1,2));
          $this->view->extraURL = $unit;

        }

        $filter1 = array();
        $filter1[] = "SATKER IN (SELECT KDSATKER FROM T_SATKER WHERE KANWIL_DJPB = '" . $unit . "') ";

        $filter2 = array();
        $filter2[] = "KDKPPN IN (SELECT KDKPPN FROM T_KPPN WHERE KDKANWIL = '" . substr($unit,1,2) . "') ";

        $filter3 = array();
        $filter3[] = "A.SEGMENT1 IN (SELECT KDSATKER FROM T_SATKER WHERE KANWIL_DJPB = '" . $unit . "') ";

        $filter5 = array();
        $filter5[] = "KDKPPN IN (SELECT KDKPPN FROM T_KPPN WHERE KDKANWIL =  '" . substr($unit,1,2) . "') ";

        $belanjaHariIni = $fetch->fetchRealisasiPaguBelanja($filter1);
        $penerimaanHariIni = $fetch->sumRealisasiPenerimaan($filter1);
        $kontrakHariIni =  $fetch->fetchStatusRealisasiKontrak($filter3);
        $returHariIni = $fetch->fetchStatusRetur($filter5);
        $lhpHariIni = $fetch->get_lhp_rekap(1, " KANWIL = '" . substr($unit,1,2) . "' ");
        $sp2dHariIni = $fetch->fetchRekapSP2DTahunIni($filter2);

        if (!isset($mode) || ($mode == 1)) {

          $filter5 = array();
          $filter5[] = "B.KANWIL_DJPB = '" . $unit . "'";

          $detailRealisasi = $fetch->get_realisasi_dash_filter($filter5);

          $mainchartData = array();

          if ($detailRealisasi[0]->get_pagu_51() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_51() / $detailRealisasi[0]->get_pagu_51() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_52() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_52() / $detailRealisasi[0]->get_pagu_52() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_53() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_53() / $detailRealisasi[0]->get_pagu_53() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_54() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_54() / $detailRealisasi[0]->get_pagu_54() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_55() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_55() / $detailRealisasi[0]->get_pagu_55() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_56() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_56() / $detailRealisasi[0]->get_pagu_56() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_57() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_57() / $detailRealisasi[0]->get_pagu_57() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_58() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_58() / $detailRealisasi[0]->get_pagu_58() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_61() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_61() / $detailRealisasi[0]->get_pagu_61() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer'),
            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' %', $mainchartData[1] . ' %', $mainchartData[2] . ' %', $mainchartData[3] . ' %', $mainchartData[4] . ' %', $mainchartData[5] . ' %', $mainchartData[6] . ' %', $mainchartData[7] . ' %', $mainchartData[8] . ' %'),
                'colors' => array('#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4')

              )

          );

        } else if ($mode == 2) {

          $filter5 = array();
          $filter5[] = "B.KANWIL_DJPB = '" . $unit . "'";

          $detailRealisasi = $fetch->get_realisasi_numbers_dash_filter($filter5);

          $mainchartData = array();
          $mainchartData2 = array();

          if ($detailRealisasi[0]->get_belanja_51() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_51() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_52() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_52() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_53() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_53() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_54() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_54() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_55() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_55() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_56() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_56() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_57() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_57() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_58() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_58() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_61() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_61() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_41() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_41()  * -1 / 10000000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData2[] = 0;
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_42() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_42()  * -1 / 10000000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData2[] = 0;
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis',

            'datasets' => array(

                (object) array(

                  'name' => 'Realisasi Belanja (dalam Triliun Rupiah)',
                  'values' => $mainchartData

                  ),
                (object) array(

                  'name' => 'Realisasi Penerimaan (dalam Triliun Rupiah)',
                  'values' => $mainchartData2

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer', 'Pajak', 'PNBP'),

            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' Triliun', $mainchartData[1] . ' Triliun', $mainchartData[2] . ' Triliun', $mainchartData[3] . ' Triliun', $mainchartData[4] . ' Triliun', $mainchartData[5] . ' Triliun', $mainchartData[6] . ' Triliun', $mainchartData[7] . ' Triliun', $mainchartData[8] . ' Triliun', $mainchartData2[9] . ' Triliun', $mainchartData2[10] . ' Triliun'),
                'colors' => array('#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#ff6666', '#1f77b4', '#1f77b4')

              ),

            'colors' => array('#ff6666', '#1f77b4')

          );

        }  else if ($mode == 3) {

          $filtermain = array();
          $filtermain[] = "KANWIL = '" . substr($unit,1,2) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnit(1,1,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Tertinggi per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        } else if ($mode == 4) {

          $filtermain = array();
          $filtermain[] = "KANWIL = '" . substr($unit,1,2) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnit(1,2,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Terendah per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        } else if ($mode == 5) {

          $filtermain = array();
          $filtermain[] = "KANWIL = '" . substr($unit,1,2) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitAll(2,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(2, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja per KPPN',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        } else if ($mode == 6) {

          $rekapUnit = $fetch->get_sp2d_rekap_tabel($unit,$lhpHariIni[0]->get_tgl_lhp());

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'table-legacy-summary',
            'title' => 'Rekapitulasi Status SPM, SP2D, dan LHP KPPN (Hari Ini)',

            'summary_rows' => $rekapUnit

          );

        }

        $this->view->content = (object) array(

            'title' => 'Dashboard',
            'subtitle' => 'KANWIL ' . $namaUnit,
            'type' => 'overview-default',

            'status_tiles' => array(

                (object) array(

                    'type' => 'pie',
                    'title' => 'Penerbitan SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Gaji',
                          'value' => $sp2dHariIni->get_gaji()

                          ),

                        (object) array(

                          'name' => 'Non Gaji',
                          'value' => $sp2dHariIni->get_non_gaji()

                          ),

                        (object) array(

                          'name' => 'Retur',
                          'value' => $sp2dHariIni->get_retur()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $sp2dHariIni->get_lainnya()

                          ),

                        (object) array(

                          'name' => 'Void',
                          'value' => $sp2dHariIni->get_void()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#CF8CD7', '#CCCCCC', '#FF6666')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Belanja',
                    'subtitle' => round($belanjaHariIni->get_realisasi() / 100000000000) / 10 . ' Triliun (' . round($belanjaHariIni->get_realisasi() / $belanjaHariIni->get_pagu() * 1000) / 10 . ' %) <br/>Dari Pagu Belanja ' . round($belanjaHariIni->get_pagu() / 100000000000) / 10 .' Triliun ',
                    'value' => round($belanjaHariIni->get_realisasi() / 100000000000) / 10,
                    'max_value' => round($belanjaHariIni->get_pagu() / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Penerimaan',
                    'subtitle' => round($penerimaanHariIni / 100000000000) / 10 . ' Triliun <br/>Tidak ada data pagu',
                    'value' => round($penerimaanHariIni / 100000000000) / 10,
                    'max_value' => round($penerimaanHariIni / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'pie',
                    'title' => 'Retur SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Sudah Proses',
                          'value' => $returHariIni->get_retur_sudah_proses() . ' Penerima'

                          ),

                        (object) array(

                          'name' => 'Belum Proses',
                          'value' => $returHariIni->get_retur_belum_proses() . ' Penerima'

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Pencairan Kontrak',
                    'subtitle' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10 . ' Triliun (' . round($kontrakHariIni->get_pencairan() / $kontrakHariIni->get_nilai_kontrak() * 1000) / 10 . ' %) <br/>Dari Total Nilai Kontrak ' . round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10 .' Triliun ',
                    'value' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10,
                    'max_value' => round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'pie',
                    'title' => 'Status LHP (' . $lhpHariIni[0]->get_tgl_lhp() . ')',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Selesai',
                          'value' => $lhpHariIni[0]->get_lhp_completed()

                          ),

                        (object) array(

                          'name' => 'Divalidasi',
                          'value' => $lhpHariIni[0]->get_lhp_validated()

                          ),

                        (object) array(

                          'name' => 'Error',
                          'value' => $lhpHariIni[0]->get_lhp_error()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $lhpHariIni[0]->get_lhp_etc()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#FF6666', '#C995E2')

                  )

              ),

            'main_tile' => $main_tile,

            'notifications' => array()

          );
        
        //echo(json_encode($this->view->content->main_tile));

        $this->view->switchers = array();
        $this->view->switchers[] = 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja';
        $this->view->switchers[] = 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Tertinggi per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Terendah per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja per KPPN';
        $this->view->switchers[] = 'Rekapitulasi Status SPM, SP2D, dan LHP KPPN (Hari Ini)';

        $this->view->baseURL = URL . 'dashboard/overviewKanwil/';

        $this->view->render('Template-Overview');
        
    }

    public function overviewKPPN($mode, $unit=null) {

        $fetch = new DataOverview($this->registry);

        if (!isset($unit)) {

          $unit = Session::get('kd_satker');
          $this->view->extraURL = '';

        } else {
          $this->view->extraURL = $unit;
          $namaUnit = $fetch->getNamaUnit(2,$unit);
        }

        $filter1 = array();
        $filter1[] = "SATKER IN (SELECT KDSATKER FROM T_SATKER WHERE KPPN = '" . $unit . "') ";

        $filter2 = array();
        $filter2[] = "substr(INVOICE_NUM,8, 6) IN (SELECT KDSATKER FROM T_SATKER WHERE KPPN = '" . $unit . "') ";

        $filter3 = array();
        $filter3[] = "A.SEGMENT1 IN (SELECT KDSATKER FROM T_SATKER WHERE KPPN = '" . $unit . "') ";

        $filter5 = array();
        $filter5[] = "KDKPPN = '" . $unit . "'";

        $belanjaHariIni = $fetch->fetchRealisasiPaguBelanja($filter1);
        $penerimaanHariIni = $fetch->sumRealisasiPenerimaan($filter1);
        $kontrakHariIni =  $fetch->fetchStatusRealisasiKontrak($filter3);
        $returHariIni = $fetch->fetchStatusRetur($filter5);
        $lhpHariIni = $fetch->get_lhp_rekap(1, "KPPN = '" . $unit ."' ");

        $filter6 = array();
        $filter6[] = "KDKPPN = '" . $unit . "' ";
        $sp2dHariIni = $fetch->fetchRekapSP2DTahunIni($filter6);

        if (!isset($mode) || ($mode == 1)) {

          $filter5 = array();
          $filter5[] = "B.KPPN = '" . $unit . "'";

          $detailRealisasi = $fetch->get_realisasi_dash_filter($filter5);

          $mainchartData = array();

          if ($detailRealisasi[0]->get_pagu_51() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_51() / $detailRealisasi[0]->get_pagu_51() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_52() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_52() / $detailRealisasi[0]->get_pagu_52() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_53() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_53() / $detailRealisasi[0]->get_pagu_53() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_54() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_54() / $detailRealisasi[0]->get_pagu_54() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_55() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_55() / $detailRealisasi[0]->get_pagu_55() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_56() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_56() / $detailRealisasi[0]->get_pagu_56() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_57() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_57() / $detailRealisasi[0]->get_pagu_57() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_58() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_58() / $detailRealisasi[0]->get_pagu_58() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_61() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_61() / $detailRealisasi[0]->get_pagu_61() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer'),
            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' %', $mainchartData[1] . ' %', $mainchartData[2] . ' %', $mainchartData[3] . ' %', $mainchartData[4] . ' %', $mainchartData[5] . ' %', $mainchartData[6] . ' %', $mainchartData[7] . ' %', $mainchartData[8] . ' %'),
                'colors' => array('#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4')

              )

          );

        } else if ($mode == 2) {

          $filter5 = array();
          $filter5[] = "B.KPPN = '" . $unit . "'";

          $detailRealisasi = $fetch->get_realisasi_numbers_dash_filter($filter5);

          $mainchartData = array();
          $mainchartData2 = array();

          if ($detailRealisasi[0]->get_belanja_51() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_51() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_52() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_52() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_53() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_53() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_54() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_54() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_55() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_55() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_56() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_56() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_57() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_57() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_58() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_58() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_61() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_61() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_41() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_41()  * -1 / 10000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_42() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_42()  * -1 / 10000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis',

            'datasets' => array(

                (object) array(

                  'name' => 'Realisasi Belanja (dalam Miliar Rupiah)',
                  'values' => $mainchartData

                  ),
                (object) array(

                  'name' => 'Realisasi Penerimaan (dalam Miliar Rupiah)',
                  'values' => $mainchartData2

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer', 'Pajak', 'PNBP'),

            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' Miliar', $mainchartData[1] . ' Miliar', $mainchartData[2] . ' Miliar', $mainchartData[3] . ' Miliar', $mainchartData[4] . ' Miliar', $mainchartData[5] . ' Miliar', $mainchartData[6] . ' Miliar', $mainchartData[7] . ' Miliar', $mainchartData[8] . ' Miliar', $mainchartData2[9] . ' Miliar', $mainchartData2[10] . ' Miliar'),
                'colors' => array('#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#1f77b4', '#1f77b4')

              ),

            'colors' => array('#f6ce40', '#1f77b4')

          );

        } else if ($mode == 3) {

          $filtermain = array();
          $filtermain[] = "KPPN = '" . $unit . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnit(1,1,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Tertinggi per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        } else if ($mode == 4) {

          $filtermain = array();
          $filtermain[] = "KPPN = '" . $unit . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnit(1,2,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartColor = array();
          $mainchartLegend = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();
            $mainchartColor[] = '#1f77b4';

          }

          $legendLabels = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legendLabels as $legend) {

              if ($label == $legend->get_kode_unit()) {

                $mainchartLegend[$lid] = $legend->get_nama_unit();

              }

            }

          }

          //var_dump($legendLabels);

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Terendah per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartColor

              )

          );

        }

        $this->view->content = (object) array(

            'title' => 'Dashboard',
            'subtitle' => 'KPPN ' . $namaUnit,
            'type' => 'overview-default',

            'status_tiles' => array(

                (object) array(

                    'type' => 'pie',
                    'title' => 'Penerbitan SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Gaji',
                          'value' => $sp2dHariIni->get_gaji()

                          ),

                        (object) array(

                          'name' => 'Non Gaji',
                          'value' => $sp2dHariIni->get_non_gaji()

                          ),

                        (object) array(

                          'name' => 'Retur',
                          'value' => $sp2dHariIni->get_retur()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $sp2dHariIni->get_lainnya()

                          ),

                        (object) array(

                          'name' => 'Void',
                          'value' => $sp2dHariIni->get_void()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#CF8CD7', '#CCCCCC', '#FF6666')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Belanja',
                    'subtitle' => round($belanjaHariIni->get_realisasi() / 100000000000) / 10 . ' Triliun (' . round($belanjaHariIni->get_realisasi() / $belanjaHariIni->get_pagu() * 1000) / 10 . ' %) <br/>Dari Pagu Belanja ' . round($belanjaHariIni->get_pagu() / 100000000000) / 10 .' Triliun ',
                    'value' => round($belanjaHariIni->get_realisasi() / 100000000000) / 10,
                    'max_value' => round($belanjaHariIni->get_pagu() / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Penerimaan',
                    'subtitle' => round($penerimaanHariIni / 100000000000) / 10 . ' Triliun <br/>Tidak ada data pagu',
                    'value' => round($penerimaanHariIni / 100000000000) / 10,
                    'max_value' => round($penerimaanHariIni / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'pie',
                    'title' => 'Retur SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Sudah Proses',
                          'value' => $returHariIni->get_retur_sudah_proses() . ' Penerima'

                          ),

                        (object) array(

                          'name' => 'Belum Proses',
                          'value' => $returHariIni->get_retur_belum_proses() . ' Penerima'

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Pencairan Kontrak',
                    'subtitle' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10 . ' Triliun (' . round($kontrakHariIni->get_pencairan() / $kontrakHariIni->get_nilai_kontrak() * 1000) / 10 . ' %) <br/>Dari Total Nilai Kontrak ' . round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10 .' Triliun ',
                    'value' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10,
                    'max_value' => round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'pie',
                    'title' => 'Status LHP (' . $lhpHariIni[0]->get_tgl_lhp() . ')',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Selesai',
                          'value' => $lhpHariIni[0]->get_lhp_completed()

                          ),

                        (object) array(

                          'name' => 'Divalidasi',
                          'value' => $lhpHariIni[0]->get_lhp_validated()

                          ),

                        (object) array(

                          'name' => 'Error',
                          'value' => $lhpHariIni[0]->get_lhp_error()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $lhpHariIni[0]->get_lhp_etc()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#FF6666', '#C995E2')

                  )

              ),

            'main_tile' => $main_tile,

            'notifications' => array()

          );
        
        //echo(json_encode($this->view->content));

        $this->view->switchers = array();
        $this->view->switchers[] = 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja';
        $this->view->switchers[] = 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Tertinggi per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Terendah per Satker';

        $this->view->baseURL = URL . 'dashboard/overviewKPPN/';

        $this->view->render('Template-Overview');
        
    }

    public function overviewKL($mode=null) {

        $fetch = new DataOverview($this->registry);

        $filter1 = array();
        $filter1[] = "SATKER IN (SELECT KDSATKER FROM T_SATKER WHERE BA = '" . substr(Session::get('kd_satker'),2,3) . "') ";

        $filter2 = array();
        $filter2[] = "substr(INVOICE_NUM,8, 6) IN (SELECT KDSATKER FROM T_SATKER WHERE BA = '" . substr(Session::get('kd_satker'),2,3) . "') ";

        $filter3 = array();
        $filter3[] = "substr(segment4,0,3) = '" . substr(Session::get('kd_satker'),2,3) . "'";

        $filter4 = array();
        $filter4[] = "BA = '" . substr(Session::get('kd_satker'),2,3) . "'";

        $belanjaHariIni = $fetch->fetchRealisasiPaguBelanja($filter1);
        $belanjaRiilHariIni = $fetch->sumRealisasiBelanjaMenkeu($filter4);
        $penerimaanHariIni = $fetch->sumRealisasiPenerimaanMenkeu($filter4);
        $kontrakHariIni =  $fetch->fetchStatusRealisasiKontrak($filter3);

        $filter6 = array();
        $filter6[] = "SEGMENT1 IN (SELECT KDSATKER FROM T_SATKER WHERE BA = '" . substr(Session::get('kd_satker'),2,3) . "') ";
        $sp2dHariIni = $fetch->fetchRekapSP2DTahunIni($filter6);

        if (!isset($mode) || ($mode == 1)) {

          $filter5 = array();
          $filter5[] = "B.BA = '" . substr(Session::get('kd_satker'),2,3) . "'";

          $detailRealisasi = $fetch->get_realisasi_dash_filter($filter5);

          $mainchartData = array();

          if ($detailRealisasi[0]->get_pagu_51() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_51() / $detailRealisasi[0]->get_pagu_51() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_52() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_52() / $detailRealisasi[0]->get_pagu_52() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_53() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_53() / $detailRealisasi[0]->get_pagu_53() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_54() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_54() / $detailRealisasi[0]->get_pagu_54() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_55() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_55() / $detailRealisasi[0]->get_pagu_55() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_56() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_56() / $detailRealisasi[0]->get_pagu_56() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_57() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_57() / $detailRealisasi[0]->get_pagu_57() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_58() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_58() / $detailRealisasi[0]->get_pagu_58() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_61() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_61() / $detailRealisasi[0]->get_pagu_61() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer'),
            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' %', $mainchartData[1] . ' %', $mainchartData[2] . ' %', $mainchartData[3] . ' %', $mainchartData[4] . ' %', $mainchartData[5] . ' %', $mainchartData[6] . ' %', $mainchartData[7] . ' %', $mainchartData[8] . ' %'),
                'colors' => array('#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4')

              )

          );

        } else if ($mode == 2) {

          $filter5 = array();
          $filter5[] = "B.BA = '" . substr(Session::get('kd_satker'),2,3) . "'";

          $detailRealisasi = $fetch->get_realisasi_numbers_dash_filter($filter5);

          $mainchartData = array();
          $mainchartData2 = array();

          if ($detailRealisasi[0]->get_belanja_51() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_51() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_52() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_52() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_53() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_53() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_54() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_54() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_55() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_55() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_56() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_56() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_57() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_57() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_58() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_58() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_61() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_61() / 10000000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_41() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_41()  * -1 / 10000000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_42() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_42()  * -1 / 10000000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis',

            'datasets' => array(

                (object) array(

                  'name' => 'Realisasi Belanja (dalam Triliun Rupiah)',
                  'values' => $mainchartData

                  ),
                (object) array(

                  'name' => 'Realisasi Penerimaan (dalam Triliun Rupiah)',
                  'values' => $mainchartData2

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer', 'Pajak', 'PNBP'),

            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' Triliun', $mainchartData[1] . ' Triliun', $mainchartData[2] . ' Triliun', $mainchartData[3] . ' Triliun', $mainchartData[4] . ' Triliun', $mainchartData[5] . ' Triliun', $mainchartData[6] . ' Triliun', $mainchartData[7] . ' Triliun', $mainchartData[8] . ' Triliun', $mainchartData2[9] . ' Triliun', $mainchartData2[10] . ' Triliun'),
                'colors' => array('#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#1f77b4', '#1f77b4')

              ),

            'colors' => array('#f6ce40', '#1f77b4')

          );

        } else if ($mode == 3) {

          $filtermain = array();
          $filtermain[] = "B.BA = '" . substr(Session::get('kd_satker'),2,3) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(1,1,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartLegend = array();
          $mainchartLegendColor = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();

          }

          $legend = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legend as $le) {

              if ($label == $le->get_kode_unit()) {

                $mainchartLegend[$lid] = $le->get_nama_unit();
                $mainchartLegendColor[$lid] = '#1f77b4';

              }

            }

          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Tertinggi per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartLegendColor

              )

          );

        } else if ($mode == 4) {

          $filtermain = array();
          $filtermain[] = "B.BA = '" . substr(Session::get('kd_satker'),2,3) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(1,2,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartLegend = array();
          $mainchartLegendColor = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();

          }

          $legend = $fetch->fetchNamaUnit(1, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legend as $le) {

              if ($label == $le->get_kode_unit()) {

                $mainchartLegend[$lid] = $le->get_nama_unit();
                $mainchartLegendColor[$lid] = '#1f77b4';

              }

            }

          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Terendah per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartLegendColor

              )

          );

        }  else if ($mode == 5) {

          $filtermain = array();
          $filtermain[] = "B.BA = '" . substr(Session::get('kd_satker'),2,3) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(2,1,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartLegend = array();
          $mainchartLegendColor = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();

          }

          $legend = $fetch->fetchNamaUnit(4, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legend as $le) {

              if ($label == $le->get_kode_unit()) {

                $mainchartLegend[$lid] = $le->get_nama_unit();
                $mainchartLegendColor[$lid] = '#1f77b4';

              }

            }

          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Tertinggi per ES1',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartLegendColor

              )

          );

        } else if ($mode == 6) {

          $filtermain = array();
          $filtermain[] = "B.BA = '" . substr(Session::get('kd_satker'),2,3) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(2,2,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();
          $mainchartLegend = array();
          $mainchartLegendColor = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();

          }

          $legend = $fetch->fetchNamaUnit(4, $mainchartLabel);

          foreach ($mainchartLabel as $lid=>$label) {

            foreach ($legend as $le) {

              if ($label == $le->get_kode_unit()) {

                $mainchartLegend[$lid] = $le->get_nama_unit();
                $mainchartLegendColor[$lid] = '#1f77b4';

              }

            }

          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Terendah per ES1',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel,
            'legends' => (object) array(

                'labels' => $mainchartLegend,
                'colors' => $mainchartLegendColor

              )

          );

        }

        $this->view->content = (object) array(

            'title' => 'Dashboard',
            'type' => 'overview-default',

            'status_tiles' => array(

                (object) array(

                    'type' => 'pie',
                    'title' => 'Penerbitan SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Gaji',
                          'value' => $sp2dHariIni->get_gaji()

                          ),

                        (object) array(

                          'name' => 'Non Gaji',
                          'value' => $sp2dHariIni->get_non_gaji()

                          ),

                        (object) array(

                          'name' => 'Retur',
                          'value' => $sp2dHariIni->get_retur()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $sp2dHariIni->get_lainnya()

                          ),

                        (object) array(

                          'name' => 'Void',
                          'value' => $sp2dHariIni->get_void()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#CF8CD7', '#CCCCCC', '#FF6666')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Belanja',
                    'subtitle' => round($belanjaRiilHariIni / 100000000000) / 10 . ' Triliun (' . round($belanjaRiilHariIni / $belanjaHariIni->get_pagu() * 1000) / 10 . ' %) <br/>Dari Pagu Belanja ' . round($belanjaHariIni->get_pagu() / 100000000000) / 10 .' Triliun ',
                    'value' => round($belanjaRiilHariIni / 100000000000) / 10,
                    'max_value' => round($belanjaHariIni->get_pagu() / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Penerimaan',
                    'subtitle' => round($penerimaanHariIni / 100000000000) / 10 . ' Triliun <br/>Tidak ada data pagu',
                    'value' => round($penerimaanHariIni / 100000000000) / 10,
                    'max_value' => round($penerimaanHariIni / 100000000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Pencairan Kontrak',
                    'subtitle' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10 . ' Triliun (' . round($kontrakHariIni->get_pencairan() / $kontrakHariIni->get_nilai_kontrak() * 1000) / 10 . ' %) <br/>Dari Total Nilai Kontrak ' . round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10 .' Triliun ',
                    'value' => round($kontrakHariIni->get_pencairan() / 100000000000) / 10,
                    'max_value' => round($kontrakHariIni->get_nilai_kontrak() / 100000000000) / 10

                  )

              ),

            'main_tile' => $main_tile,

            'notifications' => array()

          );
        
        $this->view->switchers = array();
        $this->view->switchers[] = 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja';
        $this->view->switchers[] = 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Tertinggi per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Terendah per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Tertinggi per ES1';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Terendah per ES1';

        $this->view->baseURL = URL . 'dashboard/overviewKL/';

        $this->view->render('Template-Overview');
        
    }

    public function overviewES1($mode=null) {
        
        $fetch = new DataOverview($this->registry);

        $filter1 = array();
        $filter1[] = "SATKER IN (SELECT KDSATKER FROM T_SATKER WHERE BAES1 = '" . substr(Session::get('kd_satker'),1,5) . "') ";

        $filter2 = array();
        $filter2[] = "substr(INVOICE_NUM,8, 6) IN (SELECT KDSATKER FROM T_SATKER WHERE BAES1 = '" . substr(Session::get('kd_satker'),1,5) . "') ";

        $filter3 = array();
        $filter3[] = "substr(segment4,0,5) = '" . substr(Session::get('kd_satker'),1,5) . "'";

        $belanjaHariIni = $fetch->fetchRealisasiPaguBelanja($filter1);
        $penerimaanHariIni = $fetch->sumRealisasiPenerimaan($filter1);
        $kontrakHariIni =  $fetch->fetchStatusRealisasiKontrak($filter3);

        $filter6 = array();
        $filter6[] = "SEGMENT1 IN (SELECT KDSATKER FROM T_SATKER WHERE BAES1 = '" . substr(Session::get('kd_satker'),1,5) . "') ";
        $sp2dHariIni = $fetch->fetchRekapSP2DTahunIni($filter6);

        if (!isset($mode) || ($mode == 1)) {

          $filter5 = array();
          $filter5[] = "B.BAES1 = '" . substr(Session::get('kd_satker'),1,5) . "'";

          $detailRealisasi = $fetch->get_realisasi_dash_filter($filter5);

          $mainchartData = array();

          if ($detailRealisasi[0]->get_pagu_51() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_51() / $detailRealisasi[0]->get_pagu_51() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_52() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_52() / $detailRealisasi[0]->get_pagu_52() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_53() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_53() / $detailRealisasi[0]->get_pagu_53() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_54() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_54() / $detailRealisasi[0]->get_pagu_54() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_55() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_55() / $detailRealisasi[0]->get_pagu_55() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_56() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_56() / $detailRealisasi[0]->get_pagu_56() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_57() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_57() / $detailRealisasi[0]->get_pagu_57() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_58() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_58() / $detailRealisasi[0]->get_pagu_58() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_61() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_61() / $detailRealisasi[0]->get_pagu_61() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer'),
            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' %', $mainchartData[1] . ' %', $mainchartData[2] . ' %', $mainchartData[3] . ' %', $mainchartData[4] . ' %', $mainchartData[5] . ' %', $mainchartData[6] . ' %', $mainchartData[7] . ' %', $mainchartData[8] . ' %'),
                'colors' => array('#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4')

              )

          );

        } else if ($mode == 2) {

          $filter5 = array();
          $filter5[] = "B.BAES1 = '" . substr(Session::get('kd_satker'),1,5) . "'";

          $detailRealisasi = $fetch->get_realisasi_numbers_dash_filter($filter5);

          $mainchartData = array();
          $mainchartData2 = array();

          if ($detailRealisasi[0]->get_belanja_51() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_51() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_52() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_52() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_53() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_53() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_54() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_54() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_55() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_55() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_56() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_56() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_57() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_57() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_58() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_58() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_61() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_61() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_41() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_41()  * -1 / 10000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_42() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_42()  * -1 / 10000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis',

            'datasets' => array(

                (object) array(

                  'name' => 'Realisasi Belanja (dalam Miliar Rupiah)',
                  'values' => $mainchartData

                  ),
                (object) array(

                  'name' => 'Realisasi Penerimaan (dalam Miliar Rupiah)',
                  'values' => $mainchartData2

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer', 'Pajak', 'PNBP'),

            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' Miliar', $mainchartData[1] . ' Miliar', $mainchartData[2] . ' Miliar', $mainchartData[3] . ' Miliar', $mainchartData[4] . ' Miliar', $mainchartData[5] . ' Miliar', $mainchartData[6] . ' Miliar', $mainchartData[7] . ' Miliar', $mainchartData[8] . ' Miliar', $mainchartData2[9] . ' Miliar', $mainchartData2[10] . ' Miliar'),
                'colors' => array('#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#1f77b4', '#1f77b4')

              ),

            'colors' => array('#f6ce40', '#1f77b4')

          );

        } else if ($mode == 3) {

          $filtermain = array();
          $filtermain[] = "B.BAES1 = '" . substr(Session::get('kd_satker'),1,5) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(1,1,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();

          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Tertinggi per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel

          );

        } else if ($mode == 4) {

          $filtermain = array();
          $filtermain[] = "B.BAES1 = '" . substr(Session::get('kd_satker'),1,5) . "' ";

          $realisasiPerUnit = $fetch->fetchRealisasiPaguBelanjaPerUnitBAES1(1,2,$filtermain);

          $mainchartData = array();
          $mainchartLabel = array();

          foreach ($realisasiPerUnit as $unitData) { 

            $mainchartData[] = round($unitData->get_realisasi() / $unitData->get_pagu() * 1000) / 10;
            $mainchartLabel[] = $unitData->get_unit();

          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Terendah per Satker',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => $mainchartLabel

          );

        }

        $this->view->content = (object) array(

            'title' => 'Dashboard',
            'type' => 'overview-default',

            'status_tiles' => array(

                (object) array(

                    'type' => 'pie',
                    'title' => 'Penerbitan SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Gaji',
                          'value' => $sp2dHariIni->get_gaji()

                          ),

                        (object) array(

                          'name' => 'Non Gaji',
                          'value' => $sp2dHariIni->get_non_gaji()

                          ),

                        (object) array(

                          'name' => 'Retur',
                          'value' => $sp2dHariIni->get_retur()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $sp2dHariIni->get_lainnya()

                          ),

                        (object) array(

                          'name' => 'Void',
                          'value' => $sp2dHariIni->get_void()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#CF8CD7', '#CCCCCC', '#FF6666')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Belanja',
                    'subtitle' => round($belanjaHariIni->get_realisasi() / 100000000) / 10 . ' Miliar (' . round($belanjaHariIni->get_realisasi() / $belanjaHariIni->get_pagu() * 1000) / 10 . ' %) <br/>Dari Pagu Belanja ' . round($belanjaHariIni->get_pagu() / 100000000) / 10 .' Miliar ',
                    'value' => round($belanjaHariIni->get_realisasi() / 100000000) / 10,
                    'max_value' => round($belanjaHariIni->get_pagu() / 100000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Penerimaan',
                    'subtitle' => round($penerimaanHariIni / 100000000) / 10 . ' Miliar <br/>Tidak ada data pagu',
                    'value' => round($penerimaanHariIni / 100000000) / 10,
                    'max_value' => round($penerimaanHariIni / 100000000) / 10

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Pencairan Kontrak',
                    'subtitle' => round($kontrakHariIni->get_pencairan() / 100000000) / 10 . ' Miliar (' . round($kontrakHariIni->get_pencairan() / $kontrakHariIni->get_nilai_kontrak() * 1000) / 10 . ' %) <br/>Dari Total Nilai Kontrak ' . round($kontrakHariIni->get_nilai_kontrak() / 100000000) / 10 .' Miliar ',
                    'value' => round($kontrakHariIni->get_pencairan() / 100000000) / 10,
                    'max_value' => round($kontrakHariIni->get_nilai_kontrak() / 100000000) / 10

                  )

              ),

            'main_tile' => $main_tile,

            'notifications' => array()

          );
        
        //echo(json_encode($this->view->content));

        $this->view->switchers = array();
        $this->view->switchers[] = 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja';
        $this->view->switchers[] = 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Tertinggi per Satker';
        $this->view->switchers[] = 'Persentase Realisasi Belanja Terendah per Satker';

        $this->view->baseURL = URL . 'dashboard/overviewES1/';

        $this->view->render('Template-Overview');
        
    }

    public function overviewSatker($mode=null) {
        
        $fetch = new DataOverview($this->registry);

        $filter1 = array();
        $filter1[] = "SATKER = '" . Session::get('kd_satker') . "'";

        $filter2 = array();
        $filter2[] = "substr(INVOICE_NUM,8, 6) = '" . Session::get('kd_satker') . "'";

        $filter3 = array();
        $filter3[] = "A.SEGMENT1 = '" . Session::get('kd_satker') . "'";

        $filter4 = array();
        $filter4[] = "SATKER_CODE = '" . Session::get('kd_satker') . "'";

        $filter5 = array();
        $filter5[] = "KDSATKER = '" . Session::get('kd_satker') . "'";

        $filter6 = array();
        $filter6[] = "SEGMENT1 = '" . Session::get('kd_satker') . "'";

        $belanjaHariIni = $fetch->fetchRealisasiPaguBelanja($filter1);
        $penerimaanHariIni = $fetch->sumRealisasiPenerimaan($filter1);
        $sp2dHariIni = $fetch->fetchRekapSP2DTahunIni($filter6);
        $kontrakHariIni =  $fetch->fetchStatusRealisasiKontrak($filter3);
        $upHariIni = $fetch->fetchTimerUP($filter4);
        $returHariIni = $fetch->fetchStatusRetur($filter5);

        if ($upHariIni->get_sisa_hari_tup() != null) {
          $stat_tup = $upHariIni->get_sisa_hari_tup() . ' Hari';
        } else {
          $stat_tup = 'N/A';
        }

        if (!isset($mode) || ($mode == 1)) {

          $filter5 = array();
          $filter5[] = "A.SATKER = '" . Session::get('kd_satker') . "'";

          $detailRealisasi = $fetch->get_realisasi_dash_filter($filter5);

          $mainchartData = array();

          if ($detailRealisasi[0]->get_pagu_51() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_51() / $detailRealisasi[0]->get_pagu_51() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_52() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_52() / $detailRealisasi[0]->get_pagu_52() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_53() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_53() / $detailRealisasi[0]->get_pagu_53() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_54() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_54() / $detailRealisasi[0]->get_pagu_54() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_55() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_55() / $detailRealisasi[0]->get_pagu_55() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_56() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_56() / $detailRealisasi[0]->get_pagu_56() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_57() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_57() / $detailRealisasi[0]->get_pagu_57() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_58() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_58() / $detailRealisasi[0]->get_pagu_58() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_pagu_61() > 0) {
            $mainchartData[] = (round($detailRealisasi[0]->get_belanja_61() / $detailRealisasi[0]->get_pagu_61() * 1000) / 10);
          } else {
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja',

            'datasets' => array(

                (object) array(

                  'name' => 'Persentase Realisasi',
                  'values' => $mainchartData

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer'),
            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' %', $mainchartData[1] . ' %', $mainchartData[2] . ' %', $mainchartData[3] . ' %', $mainchartData[4] . ' %', $mainchartData[5] . ' %', $mainchartData[6] . ' %', $mainchartData[7] . ' %', $mainchartData[8] . ' %'),
                'colors' => array('#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4', '#1f77b4')

              )

          );

        } else if ($mode == 2) {

          $filter5 = array();
          $filter5[] = "A.SATKER = '" . Session::get('kd_satker') . "'";

          $detailRealisasi = $fetch->get_realisasi_numbers_dash_filter($filter5);

          $mainchartData = array();
          $mainchartData2 = array();

          if ($detailRealisasi[0]->get_belanja_51() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_51() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_52() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_52() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_53() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_53() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_54() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_54() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_55() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_55() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_56() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_56() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_57() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_57() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_58() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_58() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_belanja_61() != null) {
            $mainchartData[] = round($detailRealisasi[0]->get_belanja_61() / 10000000) / 100;
            $mainchartData2[] = 0;
          } else {
            $mainchartData[] = 0;
            $mainchartData2[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_41() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_41()  * -1 / 10000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData2[] = 0;
            $mainchartData[] = 0;
          }

          if ($detailRealisasi[0]->get_penerimaan_42() != null) {
            $mainchartData2[] = round($detailRealisasi[0]->get_penerimaan_42()  * -1 / 10000000) / 100;
            $mainchartData[] = 0;
          } else {
            $mainchartData2[] = 0;
            $mainchartData[] = 0;
          }

          $main_tile = (object) array(

            'type' => 'bar',
            'stacked' => true,
            'title' => 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis',

            'datasets' => array(

                (object) array(

                  'name' => 'Realisasi Belanja (dalam Miliar Rupiah)',
                  'values' => $mainchartData

                  ),
                (object) array(

                  'name' => 'Realisasi Penerimaan (dalam Miliar Rupiah)',
                  'values' => $mainchartData2

                  )

              ),

            'categories' => array('Pegawai', 'Barang', 'Modal', 'Bunga', 'Subsidi', 'Hibah', 'BanSos', 'Lain-lain', 'Transfer', 'Pajak', 'PNBP'),

            'legends' => (object) array(

                'labels' => array($mainchartData[0] . ' Miliar', $mainchartData[1] . ' Miliar', $mainchartData[2] . ' Miliar', $mainchartData[3] . ' Miliar', $mainchartData[4] . ' Miliar', $mainchartData[5] . ' Miliar', $mainchartData[6] . ' Miliar', $mainchartData[7] . ' Miliar', $mainchartData[8] . ' Miliar', $mainchartData2[9] . ' Miliar', $mainchartData2[10] . ' Miliar'),
                'colors' => array('#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#f6ce40', '#1f77b4', '#1f77b4')

              ),

            'colors' => array('#f6ce40', '#1f77b4')

          );

        }

        $this->view->content = (object) array(

            'title' => 'Dashboard',
            'type' => 'overview-default',

            'status_tiles' => array(

                (object) array(

                    'type' => 'pie',
                    'title' => 'Penerbitan SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Gaji',
                          'value' => $sp2dHariIni->get_gaji()

                          ),

                        (object) array(

                          'name' => 'Non Gaji',
                          'value' => $sp2dHariIni->get_non_gaji()

                          ),

                        (object) array(

                          'name' => 'Retur',
                          'value' => $sp2dHariIni->get_retur()

                          ),

                        (object) array(

                          'name' => 'Lainnya',
                          'value' => $sp2dHariIni->get_lainnya()

                          ),

                        (object) array(

                          'name' => 'Void',
                          'value' => $sp2dHariIni->get_void()

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40', '#CF8CD7', '#CCCCCC', '#FF6666')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Belanja',
                    'subtitle' => round($belanjaHariIni->get_realisasi() / 100000000) / 10 . ' Miliar (' . round($belanjaHariIni->get_realisasi() / $belanjaHariIni->get_pagu() * 1000) / 10 . ' %) <br/>Dari Pagu Belanja ' . round($belanjaHariIni->get_pagu() / 100000000) / 10 .' Miliar ',
                    'value' => round($belanjaHariIni->get_realisasi() / 100000000) / 10,
                    'max_value' => round($belanjaHariIni->get_pagu() / 100000000) / 10

                  ),                

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Realisasi Penerimaan',
                    'subtitle' => round($penerimaanHariIni / 100000000) / 10 . ' Miliar <br/>Tidak ada data pagu',
                    'value' => round($penerimaanHariIni / 100000000) / 10,
                    'max_value' => round($penerimaanHariIni / 100000000) / 10

                  ),

                (object) array(

                    'type' => 'pie',
                    'title' => 'Retur SP2D',
                    'datasets' => array(

                        (object) array(

                          'name' => 'Sudah Proses',
                          'value' => $returHariIni->get_retur_sudah_proses() . ' Penerima'

                          ),

                        (object) array(

                          'name' => 'Belum Proses',
                          'value' => $returHariIni->get_retur_belum_proses() . ' Penerima'

                          )

                      ),

                    'colors' => array('#409ACA', '#F6CE40')

                  ),

                (object) array(

                    'type' => 'gauge',
                    'title' => 'Pencairan Kontrak',
                    'subtitle' => round($kontrakHariIni->get_pencairan() / 100000000) / 10 . ' Miliar (' . round($kontrakHariIni->get_pencairan() / $kontrakHariIni->get_nilai_kontrak() * 1000) / 10 . ' %) <br/>Dari Total Nilai Kontrak ' . round($kontrakHariIni->get_nilai_kontrak() / 100000000) / 10 .' Miliar ',
                    'value' => round($kontrakHariIni->get_pencairan() / 100000000) / 10,
                    'max_value' => round($kontrakHariIni->get_nilai_kontrak() / 100000000) / 10

                  ),

                (object) array(

                    'type' => 'bar',
                    'title' => 'Sisa Waktu UP & TUP',
                    'subtitle' => 'UP: ' . $upHariIni->get_sisa_hari_up() . ' Hari<br/>TUP: ' . $stat_tup,
                    'datasets' => array(

                      (object) array(

                        'name' => 'Sisa Waktu',
                        'values' => array(

                            $upHariIni->get_sisa_hari_up(),
                            (0 + $upHariIni->get_sisa_hari_tup())

                          )

                        )

                      ),

                    'categories' => array('UP', 'TUP')

                  )

              ),

            'main_tile' => $main_tile,

            'notifications' => array()

          );
        
        //echo(json_encode($this->view->content));

        if ($upHariIni->get_sisa_hari_up() <= 7) {

          if ($upHariIni->get_sisa_hari_up() > 0) {

            $this->view->notifications[] = (object) array(

              'type' => 'warning',
              'message' => 'Batas pertanggungjawaban UP Satuan Kerja Anda akan jatuh tempo dalam ' . $upHariIni->get_sisa_hari_up() . ' hari lagi.'

            );

          } else {

            $this->view->notifications[] = (object) array(

              'type' => 'danger',
              'message' => 'Pertanggungjawaban UP Satuan Kerja Anda telah jatuh tempo sejak ' . $upHariIni->get_sisa_hari_up() * -1 . ' hari lalu.'

            );

          }

        }

        if ($stat_tup != 'N/A') {

          if ($upHariIni->get_sisa_hari_tup() <= 7) {

            if ($upHariIni->get_sisa_hari_tup() > 0) {

              $this->view->notifications[] = (object) array(

                'type' => 'warning',
                'message' => 'Batas pertanggungjawaban TUP Satuan Kerja Anda akan jatuh tempo dalam ' . $upHariIni->get_sisa_hari_tup() . ' hari lagi.'

              );

            } else {

              $this->view->notifications[] = (object) array(

                'type' => 'danger',
                'message' => 'Pertanggungjawaban TUP Satuan Kerja Anda telah jatuh tempo sejak ' . $upHariIni->get_sisa_hari_tup() * -1 . ' hari lalu.'

              );

            }

          }

        }

        $this->view->switchers = array();
        $this->view->switchers[] = 'Persentase Realisasi Belanja Berdasarkan Jenis Belanja';
        $this->view->switchers[] = 'Nominal Realisasi Penerimaan & Belanja Berdasarkan Jenis';

        $this->view->baseURL = URL . 'dashboard/overviewSatker/';

        $this->view->render('Template-Overview');
        
    }

    public function __destruct() {
        
    }
    
}

?>